#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++) cin >> arr[i];
	vector<int> dp_up(n, 1), dp_down(n, 1);
	for (int i = 1; i < n; i++)
		for (int j = 0; j < i; j++)
			if (arr[j] < arr[i]) dp_up[i] = max(dp_up[i], dp_up[j] + 1);

	for (int i = n - 2; i >= 0; i--)
		for (int j = n - 1; j > i; j--)
			if (arr[j] < arr[i]) dp_down[i] = max(dp_down[i], dp_down[j] + 1);

	int ret = 0;
	for (int i = 0; i < n; i++)
		ret = max(ret, dp_up[i] + dp_down[i] - 1);
	cout << n - ret << endl;
}